import util from '../../utils/util.js';
//获取应用实例
const app = getApp()
let self
// pages/list/list.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userRole:[],
    userFace:'',
    userInfo:null,
    menuList:[],
    myMenu:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    self = this;
    wx.getStorage({
      key: 'userInfo',
      success: function (result) {
        self.setData({
          userFace: result.data.avatarUrl
        })
      },
    })
    /**角色菜单设置*/ 
    util.getRole().then(res=>{
      self.data.userRole = res;
      let indexMenu, myMenuList;
      res.forEach(el=>{
        switch (el){
          case 'jz_user':
             indexMenu = [
              { name: '报修', url: '/pages/repair/repair', icon:'icon-yibaoxiu'},
               { name: '备件库', url: '/pages/partsList/partsList', icon: 'icon-beijian' },
               { name: '零件库', url: '/pages/materialList/materialList', icon: 'icon-lingjian' },
              { name: '机器列表', url: '/pages/machineList/machineList', icon: 'icon-jiqi' }
            ]
             myMenuList=[
              { name: '我的报修单', url: '/pages/repairList/repairList', icon: 'icon-order-mine', style:'circle-yellow'},
               { name: '我的自修单', url: '/pages/selfRepairList/selfRepairList', icon: 'icon-weixiugongdan', style: 'circle-blue'},
           ]
            self.data.menuList = self.data.menuList.concat(indexMenu);
            self.data.myMenu = self.data.myMenu.concat(myMenuList);
          break;
          case 'jy_user':
             indexMenu=[
              { name: '报修处理', url: '/pages/repairList/repairList?state=0', icon: 'icon-order-pending' },
               { name: '备件库', url: '/pages/partsList/partsList', icon: 'icon-beijian' },
              { name: '零件库', url: '/pages/materialList/materialList', icon: 'icon-lingjian' },
              {name: '机器列表', url: '/pages/machineList/machineList', icon: 'icon-jiqi'}
             ];
             myMenuList=[
               { name: '我的维修单', url: '/pages/sendRepairList/sendRepairList', icon: 'icon-weixiujilu', style: 'circle-blue' },
               { name: '我的保养单', url: '/pages/maintainList/maintainList', icon: 'icon-responseOrder', style: 'circle-yellow' }
             ];
            self.data.menuList = self.data.menuList.concat(indexMenu);
            self.data.myMenu = self.data.myMenu.concat(myMenuList);
          break;
        }
      })
      self.setData({
        userRole: self.data.userRole,
        menuList: self.data.menuList,
        myMenu: self.data.myMenu
      })
      return util.getUserInfo(res)
      /**角色相关信息*/ 
    }).then(res=>{
      self.data.userInfo=res.content;
      if (self.data.userRole.indexOf("jy_user")>-1){
        self.data.userInfo.roleName = "佳颖用户"
      }else{
        self.data.userInfo.roleName = (self.data.userInfo.plasmaStationName ? self.data.userInfo.plasmaStationName:'')+'浆站用户'
      }
        self.setData({
          userInfo: self.data.userInfo
        })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**首页菜单跳转*/ 
  goNavigate(e){
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    })
  }
})
